package com.woniu.controller.homepage;

import com.woniu.entity.Orders;
import com.woniu.entity.Sorting;
import com.woniu.service.homePage.ISortingAppService;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author 陈乙嘉
 * @data 2023/3/12 14:22
 */
@RestController
@RequestMapping("/app")
public class SortingAppController {

    @Autowired
    private ISortingAppService sortingAppService;

    @RequestMapping("getSortingOrderCount")
    public ResData<?> getSortingOrderCount(@RequestBody Orders orders){
        return sortingAppService.getSortingOrderCount(orders.getSorterId(), orders.getSortingBeginTime(), orders.getSortingEndTime());
    }

    @RequestMapping("findOrdersByConditions")
    public ResData<?> findOrdersByConditions(@RequestBody Orders orders){
        return sortingAppService.findOrdersByConditions(orders.getSorterId(),
                orders.getStatus());
    }

    @RequestMapping("updateOrderStatusAndSortingTime")
    public ResData<?> updateOrderStatus(@RequestBody Orders orders){
        return sortingAppService.updateOrderStatus(orders);
    }

    @RequestMapping("findGoodsDetails")
    public ResData<?> findGoodsDetails(String ordersId){
        return sortingAppService.findOrdersDetailsByOrderId(ordersId);

    }

    @RequestMapping("updateSorterId")
    public ResData<?> updateSorterId(@RequestBody Orders orders){
        return sortingAppService.updateSorterId(orders);

    }

    @RequestMapping("sorterLogin")
    public ResData<?> sorterLogin(String phone,String password){
        return sortingAppService.sorterLogin(phone, password);

    }

    @RequestMapping("getSorterIdByPhone")
    public ResData<?> getSorterIdByPhone(String phone){
        return sortingAppService.getSorterIdByPhone(phone);
    }

    //根据手机号查询工作人员所有信息
    @RequestMapping("queryWorkUser")
    public ResData<?> queryWorkUser(String phone){
        return sortingAppService.queryWorkUser(phone);
    }

    //根据手机号修改工作人员密码
    @RequestMapping("updatePasswordByPhone")
    public ResData<?> updatePasswordByPhone(String phone,String password){
        return sortingAppService.updatePasswordByPhone(phone,password);
    }


    //根据分拣员id 和订单号查询所有分拣信息
    @RequestMapping("/findSorting")
    public ResData<?> getSorting(String orderId,Integer sorterId){
        ResData<?> sorting = sortingAppService.findSorting(orderId,sorterId);
        return sorting;
    }


    //插入分拣表信息
    @RequestMapping("/insertSorting")
    public ResData<?> insertSoring(@RequestBody Sorting sorting){
        return sortingAppService.insertSorting(sorting);

    }

    //当分拣已完成修改分拣表状态
    @RequestMapping("/updateSorting")
    public ResData<?> updateSorting(Integer state,String orderId, Integer userId){
        return sortingAppService.updateSorting(state,orderId,userId);

    }

}
